package com.ccrfid.rmc6.service.personnel;

import com.ccrfid.rmc6.entity.personnel.PersonnelEntity;
import com.ccrfid.rmc6.pojo.amq.AmqPersonnel;
import com.ccrfid.rmc6.service.amq.MqMsgProducer;
import com.ccrfid.rmc6.util.JsonUtil;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class SyncPrisonerServiceAspect {
    private static final Logger logger = LoggerFactory.getLogger(SyncPrisonerServiceAspect.class);
    @Autowired
    private MqMsgProducer mqMsgProducer;

    @AfterReturning(value = "execution(public * com.ccrfid.rmc6.service.personnel.SyncPrisonerService.updatePrisonerInfoSelfBindCreate(..))",
            returning = "ret")
    public void afterUpdatePrisonerInfoSelfBindCreate(PersonnelEntity ret) {
        AmqPersonnel msgPersonnel = new AmqPersonnel(ret);
        String msg = JsonUtil.INSTANCE.writeValueAsString(msgPersonnel);
        mqMsgProducer.send2Topic("ws_personnel_add", msg);
    }

    @AfterReturning(value = "execution(public * com.ccrfid.rmc6.service.personnel.SyncPrisonerService.updatePrisonerInfoSelfBindUpdateByPersonnelSn(..))",
            returning = "ret")
    public void afterUpdatePrisonerInfoSelfBindUpdateByPersonnelSn(PersonnelEntity ret) {
        AmqPersonnel msgPersonnel = new AmqPersonnel(ret);
        String msg = JsonUtil.INSTANCE.writeValueAsString(msgPersonnel);
        mqMsgProducer.send2Topic("ws_personnel_update", msg);
    }

    @AfterReturning(value = "execution(public * com.ccrfid.rmc6.service.personnel.SyncPrisonerService.updatePrisonerInfoSelfBindUpdateByUnifoNo(..))",
            returning = "ret")
    public void afterUpdatePrisonerInfoSelfBindUpdateByUnifoNo(PersonnelEntity ret) {
        AmqPersonnel msgPersonnel = new AmqPersonnel(ret);
        String msg = JsonUtil.INSTANCE.writeValueAsString(msgPersonnel);
        mqMsgProducer.send2Topic("ws_personnel_update", msg);
    }

    @AfterReturning(value = "execution(public * com.ccrfid.rmc6.service.personnel.SyncPrisonerService.updatePrisonerInfo3rdBindCreate(..))",
            returning = "ret")
    public void afterUpdatePrisonerInfo3rdBindCreate(PersonnelEntity ret) {
        AmqPersonnel msgPersonnel = new AmqPersonnel(ret);
        String msg = JsonUtil.INSTANCE.writeValueAsString(msgPersonnel);
        mqMsgProducer.send2Topic("ws_personnel_add", msg);
    }

    @AfterReturning(value = "execution(public * com.ccrfid.rmc6.service.personnel.SyncPrisonerService.updatePrisonerInfo3rdBindUpdate(..))",
            returning = "ret")
    public void afterUpdatePrisonerInfo3rdBindUpdate(PersonnelEntity ret) {
        AmqPersonnel msgPersonnel = new AmqPersonnel(ret);
        String msg = JsonUtil.INSTANCE.writeValueAsString(msgPersonnel);
        mqMsgProducer.send2Topic("ws_personnel_update", msg);
    }

    @AfterReturning(value = "execution(public * com.ccrfid.rmc6.service.personnel.SyncPrisonerService.updatePoliceInfoSelfBindCreate(..))",
            returning = "ret")
    public void afterUpdatePoliceInfoSelfBindCreate(PersonnelEntity ret) {
        AmqPersonnel msgPersonnel = new AmqPersonnel(ret);
        String msg = JsonUtil.INSTANCE.writeValueAsString(msgPersonnel);
        mqMsgProducer.send2Topic("ws_personnel_add", msg);
    }

    @AfterReturning(value = "execution(public * com.ccrfid.rmc6.service.personnel.SyncPrisonerService.updatePoliceInfoSelfBindUpdate(..))",
            returning = "ret")
    public void afterUpdatePoliceInfoSelfBindUpdate(PersonnelEntity ret) {
        AmqPersonnel msgPersonnel = new AmqPersonnel(ret);
        String msg = JsonUtil.INSTANCE.writeValueAsString(msgPersonnel);
        mqMsgProducer.send2Topic("ws_personnel_update", msg);
    }

    @AfterReturning(value = "execution(public * com.ccrfid.rmc6.service.personnel.SyncPrisonerService.updatePoliceInfo3rdBindCreate(..))",
            returning = "ret")
    public void afterUpdatePoliceInfo3rdBindCreate(PersonnelEntity ret) {
        AmqPersonnel msgPersonnel = new AmqPersonnel(ret);
        String msg = JsonUtil.INSTANCE.writeValueAsString(msgPersonnel);
        mqMsgProducer.send2Topic("ws_personnel_add", msg);
    }

    @AfterReturning(value = "execution(public * com.ccrfid.rmc6.service.personnel.SyncPrisonerService.updatePoliceInfo3rdBindUpdate(..))",
            returning = "ret")
    public void afterUpdatePoliceInfo3rdBindUpdate(PersonnelEntity ret) {
        AmqPersonnel msgPersonnel = new AmqPersonnel(ret);
        String msg = JsonUtil.INSTANCE.writeValueAsString(msgPersonnel);
        mqMsgProducer.send2Topic("ws_personnel_update", msg);
    }

    @AfterReturning(value = "execution(public * com.ccrfid.rmc6.service.personnel.SyncPrisonerService.updateExternalPersonInfoSelfBindCreate(..))",
            returning = "ret")
    public void afterUpdateExternalPersonInfoSelfBindCreate(PersonnelEntity ret) {
        AmqPersonnel msgPersonnel = new AmqPersonnel(ret);
        String msg = JsonUtil.INSTANCE.writeValueAsString(msgPersonnel);
        mqMsgProducer.send2Topic("ws_personnel_add", msg);
    }

    @AfterReturning(value = "execution(public * com.ccrfid.rmc6.service.personnel.SyncPrisonerService.updateExternalPersonInfoSelfBindUpdate(..))",
            returning = "ret")
    public void afterUpdateExternalPersonInfoSelfBindUpdate(PersonnelEntity ret) {
        AmqPersonnel msgPersonnel = new AmqPersonnel(ret);
        String msg = JsonUtil.INSTANCE.writeValueAsString(msgPersonnel);
        mqMsgProducer.send2Topic("ws_personnel_update", msg);
    }

    @AfterReturning(value = "execution(public * com.ccrfid.rmc6.service.personnel.SyncPrisonerService.updateExternalPersonInfo3rdBindCreate(..))",
            returning = "ret")
    public void afterUpdateExternalPersonInfo3rdBindCreate(PersonnelEntity ret) {
        AmqPersonnel msgPersonnel = new AmqPersonnel(ret);
        String msg = JsonUtil.INSTANCE.writeValueAsString(msgPersonnel);
        mqMsgProducer.send2Topic("ws_personnel_add", msg);
    }

    @AfterReturning(value = "execution(public * com.ccrfid.rmc6.service.personnel.SyncPrisonerService.updateExternalPersonInfo3rdBindUpdate(..))",
            returning = "ret")
    public void afterUpdateExternalPersonInfo3rdBindUpdate(PersonnelEntity ret) {
        AmqPersonnel msgPersonnel = new AmqPersonnel(ret);
        String msg = JsonUtil.INSTANCE.writeValueAsString(msgPersonnel);
        mqMsgProducer.send2Topic("ws_personnel_update", msg);
    }
}
